<template>
	<view class="box-detail df-yc">
		<!-- 导航栏 -->
		<view class="navbar w100" :style="{ background: bgcolor }">
			<cu-custom :isBack="true" :showBackIcon="true">
				<block slot="backText">
					<text class="nav-title white shopro-selector-rect">茶能成事清明茶</text>
				</block>
			</cu-custom>
		</view>
		<view class="scroll_wrap">
			<scroll-view scroll-y="true">
				<view class="content-box bs df-yc">
					<view class="mt30">
						<ad></ad>
					</view>
					<view class="open-progress bs mt20 df-yc">
						<view style="color:#622129 ;" class="title fb fs32 shsc">开罐进度</view>
						<view v-if="JSON.stringify(boxDetail)!='{}'" class="progress w100 fs24 df ai">
							<view class="left"><text
									class="highlight">{{boxDetail.open_num}}/{{boxDetail.count_num}}</text></view>
							<view class="right">点亮整盒茶罐可获得的额外<text class="highlight">茶碗</text>与<text
									class="highlight">茶多酚</text>奖励</view>
						</view>
						<view class="progress-box df-yc">
							<progress :count="boxDetail.count_num" :current='boxDetail.open_num'></progress>
							<view class="box bg-cover">
								<view class="items bs wh100 df">
									<view class="item df-yc" v-for="(item,index) in boxDetail.count_num" :key="index">
										<image style="width: 99rpx;"
											:src="index<boxDetail.open_num?temImgUrl+'/!.png':temImgUrl+'/？.png'"
											mode="widthFix"></image>
										<view :style="{color: '#FFE7D5',opacity:index<boxDetail.open_num?1:0}"
											class="under df-xc">茶多酚+{{boxDetail.score*(index+1)}}</view>
									</view>
								</view>
							</view>
						</view>
						<view @click="openScan" style="color:#622129 ;" class="button df-c fb fs26">继续点亮成事茶</view>
						<view @click="jump('/pages/goods/open_history/open_history',{teabox_id:teabox_id,type:'one'})"
							style="color:#622129 ;" class="history fb fs26">开罐记录</view>
					</view>
					<view class="slogan">
						<shopro-slogan color="#999999"></shopro-slogan>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import progress from '../components/progress.vue'
	import ad from "../../index/components/ad.vue"
	export default {
		components: {
			progress,
			ad
		},
		data() {
			return {
				bgcolor: '',
				teabox_id: "",
				boxDetail: {},
				temImgUrl: this.$IMG_URL_TEMP
			};
		},
		onLoad(op) {
			this.teabox_id = this.$Route.query.teabox_id
			this.getDetail(this.$Route.query.teabox_id)
		},
		onShow() {
			this.getDetail(this.teabox_id)
		},
		created() {

		},
		methods: {
			getDetail(id) {
				this.$api('tea.checkDetail', {
					teabox_id: parseInt(id)
				}).then(res => {
					this.boxDetail = res.data
				})
			},
			jump(path, params) {
				this.$Router.push({
					path: path,
					params: params
				})
			},
			openScan() {
				let that = this
				uni.scanCode({
					success: function(res) {
						that.scan(that.codeParse(res.result))
					}
				});
			},
			scan(code) {
				const that = this
				this.$api('tea.scanAdd', {
					code
				}).then(res => {
					if (res.code == 401)
						wx.showModal({
							title: '添加失败',
							content: res.msg,
							success: function(res) {
								if (res.confirm) {
									this.$store.commit('LOGIN_TIP', true)
								} else {
									console.log('用户点击取消')
								}

							}
						})
					if (res.code == 1) {
						this.$tools.toast("添加成功")
						setTimeout(function() {
							that.jump("/pages/scan/scanSuccess/scanSuccess", {
								data: JSON.stringify(res.data),
								type: res.data.pro_type
							})
						}, 1000);
					} else if (res.code == 0) {
						setTimeout(function() {
							uni.navigateBack()
						}, 1000);
					}
				})
			},
			// url解析code
			codeParse(url) {
				let codeStr = url.split('?')[1]
				let code = codeStr.split('=')[1]
				return code
			}
		},
	}
</script>

<style lang="scss">
	.box-detail {
		height: 100vh;
	}

	.scroll_wrap {
		flex: 1;
		overflow: hidden;
	}

	scroll-view {
		height: 100%;
	}


	.nav-title {
		color: #191919;
	}

	.content-box {
		.image {
			width: 690rpx;
			height: 279rpx;
			background: #DC6572;
			border-radius: 20rpx;
		}

		.open-progress {
			width: 690rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 0 30rpx 60rpx 30rpx;

			.title {
				margin-top: 50rpx;
				margin-bottom: 60rpx;
			}

			.progress {
				justify-content: space-between;
				color: #666C73;
				font-weight: 500;

				.highlight {
					color: #A93A41;
				}
			}

			.progress-box {
				margin-top: 40rpx;

				.box {
					width: 630rpx;
					height: 442rpx;
					margin-top: 60rpx;
					background-image: url(#{$IMG_URL}/kgbg.png);

					.items {
						padding-top: 30rpx;
						flex-wrap: wrap;
						justify-content: center;
						align-items: center;

						.item {
							min-width: calc(600rpx/4);

							.under {
								width: 116rpx;
								height: 37rpx;
								background: rgba($color: #FFE7D5, $alpha: 0.1);
								border-radius: 20px;
								font-size: 20rpx;
								line-height: 37rpx;
								margin-top: 22rpx;
							}
						}
					}
				}
			}

			.button {
				width: 630rpx;
				height: 90rpx;
				background: linear-gradient(270deg, #E8B58E, #F7D9AA);
				box-shadow: 0px 3rpx 21rpx 0px rgba(196, 149, 107, 0.4);
				border-radius: 45rpx;
				margin-top: 70rpx;
			}

			.history {
				margin-top: 36rpx;
			}
		}

		.slogan {
			margin: 30rpx 0;
		}
	}
</style>
